<template>
  <div class="mbody" v-html="parsedContent"></div>
</template>

<script setup>
import { defineProps, computed } from "vue";
import { marked } from "marked";

const props = defineProps({
  content: {
    type: String,
    default: "",
  },
});

const parsedContent = computed(() => {
  if (!props.content) return "";
  if (typeof props.content !== "string") return "";
  return marked.parse(props.content);
});
</script>

<style scoped lang="less">
.mbody {
  overflow-x: auto;
  font-size: 14px;
  color: #595959;
  /deep/ p {
    margin: 8px 0;
    font-size: 14px;
    color: #595959;
  }

  /deep/ ol {
    display: block;
    list-style-type: decimal;
    padding-inline-start: 30px;
    unicode-bidi: isolate;

    li {
      list-style-type: decimal;
      margin-left: 8px;
    }
  }

  /deep/ ul {
    margin-left: 12px;
    line-height: 14px;

    li {
      line-height: 27px;
      list-style-type: circle;
      margin-left: 8px;
    }
  }

  /deep/ li {
    font-size: 14px;
  }

  /deep/ ul {
    font-size: 14px;
  }

  /deep/ h2,
  /deep/ h4,
  /deep/ h3 {
    margin: 12px 0;
    font-weight: bolder;
    font-size: 20;
  }

  /deep/ table {
    width: 100%;
    table-layout: fixed;
    /*表格宽度*/
    max-width: 65em;
    /*表格最大宽度，避免表格过宽*/
    border: 1px solid #dedede;
    /*表格外边框设置*/
    /*外边距*/
    border-collapse: collapse;
    /*使用单一线条的边框*/
    empty-cells: show;
    /*单元格无内容依旧绘制边框*/

    td {
      height: 35px;
      /*统一每一行的默认高度*/
      border: 1px solid #dedede;
      /*内部边框样式*/
      padding: 0 10px;
      /*内边距*/
    }

    th {
      font-weight: bold;
      /*加粗*/
      text-align: center !important;
      /*内容居中，加上 !important 避免被 Markdown 样式覆盖*/
      background: rgba(158, 188, 226, 0.2);
      /*背景色*/
    }

    tbody tr:nth-child(2n) {
      background: rgba(158, 188, 226, 0.12);
    }

    tr:hover {
      background: #efefef;
    }

    th {
      // white-space: nowrap;
      /*表头内容强制在一行显示*/
    }

    td {
      word-break: break-word;
    }
  }
}
</style>
